
package com.ja.controller.v1;

import com.alibaba.fastjson.JSON;
import com.ja.dao.DataMapper;
import com.ja.domain.*;
import com.ja.sevice.IUserService;
import com.ja.sevice.KongzhiService;
import com.ja.util.DataEncryptUtil;
import com.ja.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;




@Controller
@RequestMapping("/v1/lotter")
public class V1LotterController {

    @Autowired
    private DataMapper dataMapper;

    @Autowired
    private KongzhiService kongzhiService;

    @Autowired
    private IUserService userService;
    /*@Autowired
    private IV1LotterService iv1LotterService;
*/


    //热门彩
    @RequestMapping(value = "/hotLotter", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String hotLotter(HttpServletRequest request) {

       // Map<Object, Object> map = new HashMap<>();
       /* ArrayList<LotterType> lotterTypeArrayList = new ArrayList<>();
        lotterTypeArrayList.add(getLotterType(1, "二分时时彩", ""));
        lotterTypeArrayList.add(getLotterType(2, "天津时时彩", ""));
        lotterTypeArrayList.add(getLotterType(3, "北京PK拾", ""));
        lotterTypeArrayList.add(getLotterType(4, "二分PK拾", ""));
        lotterTypeArrayList.add(getLotterType(5, "新疆时时彩", ""));
        map.put("hotLotter", lotterTypeArrayList);
*/
        List<Data> list = new ArrayList<Data>();

        // map.put("code", "1");
        Data erfenssc = dataMapper.getLatestOpenData("2fssc");//根据彩种名称查出已经开奖的最新一期数据
        Data tjssc = dataMapper.getLatestOpenData("tjssc");
        Data bjpk10 = dataMapper.getLatestOpenData("bjpk10");
        Data erfenpk10 = dataMapper.getLatestOpenData("2fpk10");
        Data xjssc = dataMapper.getLatestOpenData("xjssc");

        list.add(erfenssc);
        list.add(tjssc);
        list.add(bjpk10);
        list.add(erfenpk10);
        list.add(xjssc);

        return JSON.toJSONString(list);
    }

    @RequestMapping(value = "/sidebar", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String sidebar(){
        List<LotterType> list=new ArrayList<>();
        LotterType allLotter = new LotterType(1, "allLotter", "全部彩种");
        LotterType ssc = new LotterType(2, "ssc", "时时彩");
        LotterType kuai3Lotter = new LotterType(3, "kuai3Lotter", "快3");
        LotterType choose5Lotter = new LotterType(4, "choose5Lotter", "11选5");
        LotterType pk10Lotter = new LotterType(5, "pk10Lotter", "pk10");
        LotterType pcEggLotter = new LotterType(6, "pcEggLotter", "pc蛋蛋");
        LotterType liuhecaiLotter = new LotterType(7, "liuhecaiLotter", "六合彩");
        LotterType kuaileshifenLotter = new LotterType(8, "kuaileshifenLotter", "快乐十分");
        LotterType lowsLotter = new LotterType(9, "lowsLotter", "低频彩");


        list.add(allLotter);
        list.add(ssc);
        list.add(kuai3Lotter);
        list.add(choose5Lotter);
        list.add(pk10Lotter);
        list.add(liuhecaiLotter);
        list.add(pcEggLotter);
        list.add(kuaileshifenLotter);
        list.add(lowsLotter);
        return JSON.toJSONString(list);
    }



//用户中心所有彩票信息（不需要参数）返回cname 和彩票中文名 需要token
    @RequestMapping(value = "/allLotters", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String allLotters(HttpServletRequest request) throws Exception {
        Map<String, Object> map = new HashMap<>();
        String token = request.getHeader("Token");
        String idStr = new String(DataEncryptUtil.decryptBASE64(token));
        int id = Integer.parseInt(idStr);
        User user = userService.getUserByid(id);
        if (user==null){
            map.put("msg","您还没有登录，请返回登录页面进行登录！");
        }

            ArrayList<LotterType> lotterTypeArrayList = new ArrayList<>();
            lotterTypeArrayList.add(getLotterType(1, "安徽快3", "ahk3"));
            lotterTypeArrayList.add(getLotterType(2, "广西快3", "gxk3"));
            lotterTypeArrayList.add(getLotterType(3, "江苏快3", "jsk3"));
            lotterTypeArrayList.add(getLotterType(4, "北京快3", "bjk3"));
            lotterTypeArrayList.add(getLotterType(5, "二分快3", "2fk3"));
            lotterTypeArrayList.add(getLotterType(6, "三分快3", "3fk3"));
            lotterTypeArrayList.add(getLotterType(7, "北京PK拾", "bjpk10"));
            lotterTypeArrayList.add(getLotterType(8, "幸运飞艇", "xyft"));
            lotterTypeArrayList.add(getLotterType(9, "二分PK拾", "2fpk10"));
            lotterTypeArrayList.add(getLotterType(10, "二分飞艇", "2fft"));
            lotterTypeArrayList.add(getLotterType(11, "幸运赛马", "xysm"));
            lotterTypeArrayList.add(getLotterType(12, "天津时时彩", "tjssc"));
            lotterTypeArrayList.add(getLotterType(13, "新疆时时彩", "xjssc"));
            lotterTypeArrayList.add(getLotterType(14, "二分时时彩", "2fssc"));
            lotterTypeArrayList.add(getLotterType(15, "安徽11选5", "ah11x5"));
            lotterTypeArrayList.add(getLotterType(16, "广东11选5", "gd11x5"));
            lotterTypeArrayList.add(getLotterType(17, "江西11选5", "jx11x5"));
            lotterTypeArrayList.add(getLotterType(18, "山东11选5", "sd11x5"));
            lotterTypeArrayList.add(getLotterType(19, "上海11选5", "sh11x5"));
            lotterTypeArrayList.add(getLotterType(20, "北京28", "bj28"));
            lotterTypeArrayList.add(getLotterType(21, "幸运28", "xy28"));
            lotterTypeArrayList.add(getLotterType(22, "上海时时乐", "shssl"));
            lotterTypeArrayList.add(getLotterType(23, "排列三", "pl3"));
            lotterTypeArrayList.add(getLotterType(24, "福彩3D", "fc3d"));
            lotterTypeArrayList.add(getLotterType(25, "广东快乐十分", "gdkl10f"));
            lotterTypeArrayList.add(getLotterType(26, "重庆快乐十分", "cqkl10f"));
            lotterTypeArrayList.add(getLotterType(27, "五分六合彩", "5f6hc"));
            lotterTypeArrayList.add(getLotterType(28, "百家乐", "bjl"));
            lotterTypeArrayList.add(getLotterType(29, "全部彩种", "all"));
            map.put("data", lotterTypeArrayList);

        return JSON.toJSONString(map);
    }



        //全部彩票
    @RequestMapping(value = "/allLotter", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String allLotter(HttpServletRequest request) {
        List<Object> list = new ArrayList<>();
        Data ahk3 = dataMapper.getLatestOpenData("ahk3");//根据彩种名称查出已经开奖的最新一期数据
        Data gxk3 = dataMapper.getLatestOpenData("gxk3");
        Data jsk3 = dataMapper.getLatestOpenData("jsk3");
        Data bjk3 = dataMapper.getLatestOpenData("bjk3");
        Data efk3 = dataMapper.getLatestOpenData("2fk3");
        Data sfk3 = dataMapper.getLatestOpenData("3fk3");
        Data bjpk10 = dataMapper.getLatestOpenData("bjpk10");
        Data xyft = dataMapper.getLatestOpenData("xyft");
        Data efpk10 = dataMapper.getLatestOpenData("2fpk10");
        Data efft = dataMapper.getLatestOpenData("2fft");
        Data xysm = dataMapper.getLatestOpenData("xysm");
        Data tjssc = dataMapper.getLatestOpenData("tjssc");
        Data xjssc = dataMapper.getLatestOpenData("xjssc");
        Data efssc = dataMapper.getLatestOpenData("2fssc");
        Data ah11x5 = dataMapper.getLatestOpenData("ah11x5");
        Data gd11x5 = dataMapper.getLatestOpenData("gd11x5");
        Data jx11x5 = dataMapper.getLatestOpenData("jx11x5");
        Data sd11x5 = dataMapper.getLatestOpenData("sd11x5");

        list.add(ahk3);
        list.add(gxk3);
        list.add(jsk3);
        list.add(bjk3);
        list.add(efk3);
        list.add(sfk3);
        list.add(bjpk10);
        list.add(xyft);
        list.add(efpk10);
        list.add(efft);
        list.add(xysm);
        list.add(tjssc);
        list.add(xjssc);
        list.add(efssc);
        list.add(ah11x5);
        list.add(gd11x5);
        list.add(jx11x5);
        list.add(sd11x5);

        return JSON.toJSONString(list);
    }

    //获得某个采种的最新一期中奖数据
    @RequestMapping(value = "/getNewLotterNumber", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String getNewLotternumber(HttpServletRequest request){
        String cname = request.getParameter("cname");
        List<Data> list = new ArrayList<Data>();
        Data data = dataMapper.getLatestOpenData(cname);
        list.add(data);
        return JSON.toJSONString(list);
    }


    //彩票分类
    @RequestMapping(value = "/LotterType", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String LotterType(HttpServletRequest request) {
        String type = request.getParameter("type");

        ArrayList<Object> list = new ArrayList<>();
        if(type.equals("ssc")) {

            Data efssc = dataMapper.getLatestOpenData("2fssc");
            Data tjssc = dataMapper.getLatestOpenData("tjssc");
            Data xjssc = dataMapper.getLatestOpenData("xjssc");
            list.add(efssc);
            list.add(tjssc);
            list.add(xjssc);


        }
        if(type.equals("kuai3Lotter")) {

            Data ahk3 = dataMapper.getLatestOpenData("ahk3");
            Data bjk3 = dataMapper.getLatestOpenData("bjk3");
            Data sfk3 = dataMapper.getLatestOpenData("3fk3");
            Data rfk3 = dataMapper.getLatestOpenData("2fk3");
            Data gxk3 = dataMapper.getLatestOpenData("gxk3");
            Data jsk3 = dataMapper.getLatestOpenData("jsk3");
            list.add(ahk3);
            list.add(bjk3);
            list.add(sfk3);
            list.add(rfk3);
            list.add(gxk3);
            list.add(jsk3);
        }
        if(type.equals("choose5Lotter")) {

            Data sd11x5 = dataMapper.getLatestOpenData("sd11x5");
            Data sh11x5 = dataMapper.getLatestOpenData("sh11x5");
            Data jx11x5 = dataMapper.getLatestOpenData("jx11x5");
            Data gd11x5 = dataMapper.getLatestOpenData("gd11x5");
            Data ah11x5 = dataMapper.getLatestOpenData("ah11x5");


           list.add(sd11x5);
            list.add(sh11x5);
            list.add(jx11x5);
            list.add(gd11x5);
            list.add(ah11x5);
        }
        if(type.equals("pk10Lotter")) {

            Data efpk10 = dataMapper.getLatestOpenData("2fpk10");
            Data bjpk10 = dataMapper.getLatestOpenData("bjpk10");
            Data xysm = dataMapper.getLatestOpenData("xysm");
            Data xyft = dataMapper.getLatestOpenData("xyft");
            Data efft = dataMapper.getLatestOpenData("2fft");
            list.add(efpk10);
            list.add(bjpk10);
            list.add(xysm);
            list.add(xyft);
            list.add(efft);

        }
        /*if(type.equals("liuhecaiLotter")) {

            Data wf6hc = dataMapper.getLatestOpenData("5f6hc");
            Data xg6hc = dataMapper.getLatestOpenData("xg6hc");
           list.add(wf6hc);
            list.add(xg6hc);
        }*/
        if(type.equals("kuaileshifenLotter")) {

            Data gdkl10f = dataMapper.getLatestOpenData("gdkl10f");
            Data cqkl10f = dataMapper.getLatestOpenData("cqkl10f");
            list.add(gdkl10f);
            list.add(cqkl10f);

        }
       /* if(type.equals("lowsLotter")) {

            Data shssl = dataMapper.getLatestOpenData("shssl");
            Data fc3d = dataMapper.getLatestOpenData("fc3d");
            Data pl3 = dataMapper.getLatestOpenData("pl3");
            list.add(shssl);
            list.add(fc3d);
            list.add(pl3);

        }*/

        /*if(type.equals("pcEggLotter")) {
            *//*lotterTypeArrayList.add(getLotterType(1, "bj28", "北京28"));
            lotterTypeArrayList.add(getLotterType(2, "xy28", "幸运28"));*//*
            Data bj28 = dataMapper.getLatestOpenData("bj28");
            Data xy28 = dataMapper.getLatestOpenData("xy28");
           list.add(bj28);
            list.add(xy28);
        }*/
        return JSON.toJSONString(list);
    }



    /** 获取球 */
    @RequestMapping(value = "/getQiu", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String getLotterTimes(String cname) {
        Map<String, Object> map = new HashMap<>();
        List<Kongzhi> kong = kongzhiService.getOneKongzhi(cname);
        map.put("qiu", kong);
         return JSON.toJSONString(map);
    }

    private LotterType getLotterType(int id, String name, String url) {
        LotterType lotterType = new LotterType();

        lotterType.setLotterTypeName(name);
        lotterType.setLotterTypeId(id);
        lotterType.setUrl(url);
        return lotterType;
    }
    //彩票类型类
     class LotterType {
        private int lotterTypeId;//彩票类型id
        private String lotterTypeName;//彩票名
        private String url;//彩票链接地址
        public LotterType(){}
        public LotterType(int lotterTypeId, String lotterTypeName, String url) {
            this.lotterTypeId = lotterTypeId;
            this.lotterTypeName = lotterTypeName;
            this.url = url;
        }

        public int getLotterTypeId() {
            return lotterTypeId;
        }

        public void setLotterTypeId(int lotterTypeId) {
            this.lotterTypeId = lotterTypeId;
        }

        public String getLotterTypeName() {
            return lotterTypeName;
        }

        public void setLotterTypeName(String lotterTypeName) {
            this.lotterTypeName = lotterTypeName;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }
    }


}

